//
//  MainViewController.m
//  mindlook
//
//  Created by reedhong on 11-9-24.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "AskViewController.h"
#import "VoteViewController.h"
#import "MeViewController.h"
#import "ResultViewController.h"


@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [tabBarController release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    //self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    
    HomeViewController* homeViewController = [[[HomeViewController alloc] init] autorelease];
    AskViewController* askViewController = [[[AskViewController alloc] init] autorelease];
    VoteViewController* voteViewController = [[[VoteViewController alloc] init] autorelease];
    ResultViewController* resultViewController = [[[ResultViewController alloc] init] autorelease];
    MeViewController* meViewController = [[[MeViewController alloc] init] autorelease];

    UINavigationController* navHome = [[[UINavigationController alloc]
                                              initWithRootViewController:homeViewController] autorelease];
    //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
    UITabBarItem* itemHome = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Home",@"") image:nil tag:0];
    navHome.tabBarItem = itemHome;
    [itemHome release];
    
    UINavigationController* navAsk = [[[UINavigationController alloc]
                                     initWithRootViewController:askViewController] autorelease];
    //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
    UITabBarItem* itemAsk = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Ask",@"") image:nil tag:0];
    navAsk.tabBarItem = itemAsk;
    [itemAsk release];
    
    UINavigationController* navVote = [[[UINavigationController alloc]
                                     initWithRootViewController:voteViewController] autorelease];
    //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
    UITabBarItem* itemVote = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Vote",@"") image:nil tag:0];
    navVote.tabBarItem = itemVote;
    [itemVote release];
    
    UINavigationController* navResult = [[[UINavigationController alloc]
                                     initWithRootViewController:resultViewController] autorelease];
    //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
    UITabBarItem* itemResult = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Result",@"") image:nil tag:0];
    navResult.tabBarItem = itemResult;
    [itemResult release];
    
    UINavigationController* navMe = [[[UINavigationController alloc]
                                     initWithRootViewController:meViewController] autorelease];
    //UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];
    UITabBarItem* itemMe = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Me",@"") image:nil tag:0];
    navMe.tabBarItem = itemMe;
    [itemMe release];    
    
    NSArray* controllers = [NSArray arrayWithObjects:navHome, navAsk, navVote, navResult, navMe, nil];
    
    tabBarController.viewControllers = controllers;
    

    self.view = tabBarController.view;
    self.navigationController.navigationBarHidden=YES;
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
